<?php
//签到

/**
 * @var $config
 * @var $key
 */

include("../WeSql/widget.php");
include("../WeSql/config.php");
include("../WeSql/WeSql.php");
include "api.php";

$user = $_REQUEST['user'];
$pass = $_REQUEST['pass'];

$weSql = new WeSql($config,$key);

isIpBlack($weSql,getIP());//检测ip是否被拉黑


if($user == "" or $pass == ""){
    $code = -1;
    $msg = "不能留空";
    $exception = "出现了参数为空的情况！";
}else{
    if($weSql->isSelectField("user",[
        "user" => $user
    ])) {
        isUserBlack($weSql, $user);//是否为黑名单

        isPassWord($weSql,$user,$pass);
            if($weSql->select("user","user='${user}'")['sign'] == "" or
                $weSql->select("user","user='${user}'")['sign'] < strtotime("+1 day", strtotime($weSql->select("user","user='${user}'")['sign']))
            ){
                //可以签到
                if($weSql->update("user",[
                    "sign" =>  time()
                ],"user='${user}'")){
                    $code = 1;
                    $msg = "签到成功";
                    $exception = "";
                }else{
                    $code = -1;
                    $msg = "签到失败";
                    $exception = "";
                }

            }else{
                $code = 0;
                $msg = "账号已经签到过了";
                $exception = "";
            }

    }else{
        $code = -1;
        $msg = "账号不存在";
        $exception = "数据库里信息找不到该记录账号";
    }
}
@$result = [
    "code" => $code,
    "msg" => $msg,
    "exception" => $exception
];
echo json_encode($result,JSON_UNESCAPED_UNICODE);